package com.leetcode;

/**
 * Created by Z-hong on 2022/9/22.
 */

public class LeetCode1640 {
    public boolean canFormArray(int[] arr, int[][] pieces) {
        for (int i = 0; i < pieces.length; i++) {
            if (pieces[i].length==1){
                if (getArr(arr, pieces[i][0])==-1){return false;}
            }else {
                int num=getArr(arr, pieces[i][0]);
                if (num==-1){return false;}
                for (int j = 0; j < pieces[i].length; j++) {
                    if (num>arr.length-1)return false;
                    if(pieces[i][j]!=arr[num++])return false;
                }
            }
        }
    return true;
    }

    public int getArr(int[]arr,int num){
        for (int i = 0; i < arr.length; i++) {
            if (arr[i]==num){
                return i;
            }
        }
        return -1;
    }
}
